package com.yc.baseapi;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class TestConcurrentMap {
	Map<Integer, Long> map = new HashMap<>();
	/**
	 * 普通map模拟在多线程的情况下增删数据<id，时间戳>
	 * 线程1：随机增加
	 * 线程2：随机删除
	 */
	public void m1() {
		
		new Thread(() -> {
			for (int i = 0; i < 10000; i++) {
				map.put(new Random().nextInt(100), System.currentTimeMillis());
			}
			
		}, "add").start();
		
		new Thread(() -> {
			for (int i = 0; i < 10000; i++) {
				map.remove(new Random().nextInt(100));
			}
			
		}, "remove").start();
		
	}
	
	ConcurrentMap<Integer, Long> map2 = new ConcurrentHashMap<Integer, Long>();
	public void m2() {
		
	}

	public static void main(String[] args) {
		TestConcurrentMap tm = new TestConcurrentMap();
		tm.m1();

	}

}
